package com.yanqu.road.server.timer.banquet;

import com.yanqu.road.entity.banquet.UserCrossBanquetData;
import com.yanqu.road.entity.banquet.cross.CrossBanquetMember;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.banquet.CrossBanquetMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.utils.executor.GeneralTask;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.Map;

public class CrossBanquetSyncMemberTask extends GeneralTask {

    protected Logger logger = LogManager.getLogger(CrossBanquetSyncMemberTask.class.getName());

    private long userId;
    private String banquetId;
    private int sendTime;
    private int memNum;
    private int page;


    public CrossBanquetSyncMemberTask(long userId, String banquetId, int sendTime, int memNum, int page) {
        this.userId = userId;
        this.banquetId = banquetId;
        this.sendTime = sendTime;
        this.memNum = memNum;
        this.page = page;
    }

    @Override
    public void doRun() {
        GamePlayer player = GamePlayerMgr.getOnlinePlayer(userId);
        if (player != null) {
            for(int i=page;i<=sendTime;i++){
                UserCrossBanquetData banquet = CrossBanquetMgr.getBanquet(banquetId);
                Map<Long, CrossBanquetMember> crossBanquetMemberMap = CrossBanquetMgr.getBanquetMemberMap(banquetId,memNum,i);
                if(!CrossBanquetMgr.syncBanquetMember(player,banquet,crossBanquetMemberMap)){
                    logger.error("CrossBanquet-break:index={}-sendTime={}",i,sendTime);
                    break;
                }
            }
            logger.info("CrossBanquet-over:sendTime={}",sendTime);
        }
    }
}
